package com.wei.czz.config;

import com.huaweicloud.sdk.core.http.HttpConfig;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.smsapi.v1.SMSApiClient;
import com.huaweicloud.sdk.smsapi.v1.SMSApiCredentials;
import com.wei.czz.common.property.SmsProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2025-01-15 15:55:25
 * className: HuaweiSmsConfig
 * version: 1.0
 * description:
 */
@Configuration
public class HuaweiSmsConfig {

    @Bean
    public SMSApiClient huaweiSmsClient(SmsProperty smsProperty) {
        SmsProperty.HuaweiSmsProperty huaweiSmsProperty = smsProperty.getHw();

        Region region = new Region("cn-north-4", new String[]{ huaweiSmsProperty.getEndpoint() });
        SMSApiCredentials smsApiCredentials = new SMSApiCredentials()
                .withAk(huaweiSmsProperty.getAppKey())
                .withSk(huaweiSmsProperty.getAppSecret());

        HttpConfig httpConfig = HttpConfig.getDefaultHttpConfig();
        httpConfig.withIgnoreSSLVerification(true);

        return SMSApiClient.newBuilder()
                .withHttpConfig(httpConfig)
                .withCredential(smsApiCredentials)
                .withRegion(region)
                .build();
    }
}
